#include "NDirector.h"
#include "NGame.h"
#include "NXmlParseMaster.h"
#include "NeroEngine\NCamera.h"
#include "NeroEngine\NEntity.h"
#include "NeroCore\NMemoryManager.h"

//External
#include "tinyxml.h"

using namespace Game;
using namespace Engine;

NDirector* NDirector::sInstance = NULL;

NDirector::NDirector(void)
	:mCurrentCamera(NULL)
{
}

NDirector::~NDirector(void)
{
	mCameras.begin();
}

void NDirector::Initialize()
{
	if(!sInstance)
	{
		//Create static intance of class
		sInstance = MY_NEW(Memory::HID_Rendering,"NDirector") NDirector();
		
		////Load xml file
		//sInstance->LoadXml(DIRCTOR_SCRIPT_FILE);

		////Set Initial Camera
		//if(GetGame()->GetEntity(sInstance->mInitialCamera))
		//{
		//	sInstance->mCurrentCamera = GetGame()->GetEntity(sInstance->mInitialCamera)->As<Game::NCamera>();
		//	if(sInstance->mCurrentCamera != NULL)
		//	{
		//		sInstance->mCurrentCamera->Initialize();
		//		sInstance->mCurrentCamera->SetEnabled(true);
		//	}
		//}
	}
}

void NDirector::Deinitialize()
{
	if(sInstance)
	{
		MY_DELETE(sInstance);
	}
}

NDirector* NDirector::GetInstance()
{
	return sInstance;
}

void NDirector::AddCamera(Engine::NCamera* camera)
{
	mCameras.push_back(camera);
}

void NDirector::SetCamera(const std::string& cameraName)
{
	mCurrentCamera->SetEnabled(false);
	mCurrentCamera = GetGame()->GetEntity(cameraName)->As<Engine::NCamera>();
	mCurrentCamera->SetEnabled(true);
}

void NDirector::SetInitialCamera(const std::string& cameraName)
{
	mInitialCamera = cameraName;
}

Engine::NCamera* NDirector::GetCurrentCamera()
{
	if(!mCurrentCamera && mCameras.size() > 0)
	{
		mCurrentCamera = mCameras[0];
	}

	return mCurrentCamera;
}

void NDirector::Notify(Engine::NEventPublisher*, float)
{
}

void NDirector::LoadXml(const char* file)
{
	NXML::NXmlParseMaster::GetInstance()->ParseXMl(file);
	
}